package com.token.sysflow.action;
import com.token.base.AgentAction;
import com.token.base.FuncUtil;
import com.token.base.JsonGenerator;
import com.token.base.Pl;
import com.token.sql.IntegrateSql;
import com.token.sql.PrepareSql;
import com.token.sysflow.bean.FlowFlowInfo;

import java.sql.ResultSet;

/**
 * 读取下拉数据：根据应用ID读取流程清单
 * @author chenjianxiong 2020/5/7
 */
public class ReadSubFlow implements AgentAction {

    public void executeAction(FuncUtil f) throws Exception {

    }

    public void executeAction(FuncUtil f, IntegrateSql iSql) throws Exception {
        String appKeyId = f.getUrlQueryString("appKeyId",true,"应用KeyId");
        String flowId = f.getUrlQueryString("flowId");
//        FlowFlowInfo flowInfo = new FlowFlowInfo(iSql);
        PrepareSql prepareSql = new PrepareSql(iSql);
        StringBuffer sql = new StringBuffer(50);
        sql.append("select FlowName as title,FlowId as value from ")
                .append(FlowFlowInfo.TABLE_NAME)
                .append(" where appKeyId=? and SysId=? and IsActive='1' ");
        if(flowId != null && !"".equals(flowId)){
            sql.append(" and flowId !=?");
        }

        prepareSql.setPrepare(sql);
        prepareSql.setPstValue(1,appKeyId);
        prepareSql.setPstValue(2,Pl.getSysId());
        if(flowId != null && !"".equals(flowId)){
            prepareSql.setPstValue(3,flowId);
        }

        ResultSet rs = prepareSql.executeQuery();
        f.putJsonData("data", JsonGenerator.toJsonArray(rs));
        rs.close();
        prepareSql.close();
//        flowInfo.close();
    }
}